//
// Created by LiuYou on 2021/8/11.
//

#ifndef NETRADIOLCPP_PROTOCOL_HPP
#define NETRADIOLCPP_PROTOCOL_HPP


#include "Types.hpp"


static char DEFAULT_MULTI_GROUP[] = "224.2.2.2";
static char DEFAULT_RCV_PORT[] = "1989";
//static int CHANNEL_NUM = 100;
//static int PROGRAM_LIST_CHANNEL_ID = 0;
//static int MIN_CHANNEL_ID = 1;
//static int MAX_CHANNEL_ID = MIN_CHANNEL_ID + CHANNEL_NUM - 1;
//// udp推荐长度: 512 ~ 64k 。
//static int MSG_CHANNEL_MAX = 65536 - 20 - 8;
//static int MAX_DATA = MSG_CHANNEL_MAX - sizeof( ChannelId );
//static int MSG_PROGRAM_LIST_MAX = 65536 - 20 - 8;
//static int MAX_ENTRY = MSG_PROGRAM_LIST_MAX - sizeof( ChannelId );

#define CHANNEL_NUM   100
#define PROGRAM_LIST_CHANNEL_ID   0
#define MIN_CHANNEL_ID   1
#define MAX_CHANNEL_ID   (MIN_CHANNEL_ID + CHANNEL_NUM - 1)
// udp推荐长度: 512 ~ 64k 。
#define MSG_CHANNEL_MAX   (65536 - 20 - 8)
#define MAX_DATA   (MSG_CHANNEL_MAX - sizeof( ChannelId ))
#define MSG_PROGRAM_LIST_MAX   (65536 - 20 - 8)
#define MAX_ENTRY   (MSG_PROGRAM_LIST_MAX - sizeof( ChannelId ))


class MsgChannel {
public:
    // must between MIN_CHANNEL_ID ~ MAX_CHANNEL_ID.
    ChannelId channelId;
    uint8_t data[1];

}__attribute__((packed));

class MsgProgramListEntry {
public:
    ChannelId channelId;
    uint16_t len;
    uint8_t description[1];

}__attribute__((packed));

/**
 * 节目单udp报文:
 *
 * 1 music:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 * 2 sport:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 * 3 xxxxx:xxxxxxxxxxxxxxxxxxxxxxxx
 * 4 xx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 */
class MsgProgramList {
public:
    // must be PROGRAM_LIST_CHANNEL_ID.
    ChannelId channelId;
    MsgProgramListEntry entry[1];

}__attribute__((packed));


#endif //NETRADIOLCPP_PROTOCOL_HPP
